package com.jk.service.impl;

import com.jk.dao.TreeBeanMapper;
import com.jk.dto.TreeBean;
import com.jk.service.TreeBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yzf
 * @version 1.0
 * @description: TODO
 * @date 2024/12/12 14:13
 */
@Service
public class TreeBeanServiceImpl implements TreeBeanService {

    @Autowired
    private TreeBeanMapper treeBeanMapper;
    @Override
    public List<TreeBean> findTreeBean(TreeBean treeBean) {
        Long pid = 0L;
        List<TreeBean> treeList = getNodesData(pid);
        return treeList;
    }
    private List<TreeBean> getNodesData(Long pid) {
        //根据夫id查询节点数据
        List<TreeBean> list =  treeBeanMapper.getNodesData(pid);
        //循环遍历list
        for (TreeBean treeBean : list) {
            //取出当前id值
            Long id = treeBean.getId();
            //递归调用本身方法 -->得到的是当前循环对象的子节点(nodes)
            List<TreeBean> nodes = getNodesData(id);
            //将子节点数据赋值给 children 属性
            treeBean.setChildren(nodes);
        }
        return list;
    }




}
